package oop.ex2.expression;

import oop.ex2.exceptions.UnrecognizedVariable;

public class ModFunctionNode extends FunctionNode {
	private static final int NUMBER_OF_PARAMS = 2;
	private static boolean BOUNDED_PARAMETERS = true;
	
	/**
	 * Build a function node.
	 * @param matchedString The string that caused this function to be created.
	 */
	public ModFunctionNode(String matchedString) {
		super(matchedString, NUMBER_OF_PARAMS, BOUNDED_PARAMETERS);
	}

	@Override
	public double calculateNode() throws UnrecognizedVariable {
		double denom = _children.get(1).calculateNode();

        if (denom == 0)
            throw new ArithmeticException("Divide by zero error");
        
		return _children.get(0).calculateNode() % _children.get(1).calculateNode();
	}

}
